Release 10.1A: OpenEdge Data Management:
SQL Development
Writing stored procedures
Use any text editor to write the
CREATE PROCEDUREstatement and save the source text as a text file. That way, you can easily modify the source text and try again if it generates syntax or Java compilation errors.From the command prompt, you can invoke SQL Explorer and submit the file containing the
CREATE PROCEDUREstatement as an input script, as shown in Example 9–5.
From the command prompt, you can invoke SQL Explorer and submit the file containing the
CREATE PROCEDUREstatement as an input script, as shown in Example 9–6.
The Java snippet within the
CREATE PROCEDUREstatement does not execute as a stand-alone program. Instead, it executes in the context of an application call to the method of the class created by the OpenEdge SQL Engine. This characteristic has the following implications:
- If the snippet declares any classes, it must instantiate them within the snippet to invoke their methods.
- The OpenEdge SQL Engine redirects the standard output stream to a file. This means method invocations, such as
System.out.println,will not display messages on the screen, but instead write them to that file.Invoking stored procedures
The manner in which applications call stored procedures depends on their environment.
From ODBC
From ODBC, applications use the following ODBC call escape sequence:
Use parameter markers (question marks used as placeholders) for input or output parameters to the procedure. You can also use literal values for input parameters only. OpenEdge stored procedures do not support return values in the ODBC escape sequence.
Embed the escape sequence in an ODBC
SQLExecDirectcall to execute the procedure.Example 9–7 shows a call to a stored procedure named
order_partsthat passes a single input parameter using a parameter marker.
From JDBC
The JDBC call escape sequence is the same as in ODBC, as shown:
Embed the escape sequence in a JDBC
CallableStatement.prepareCallmethod invocation.Example 9–8 shows the JDBC code parallel to the ODBC code excerpt shown in the previous example.
Modifying and deleting stored procedures
To modify a procedure, you must drop and re-create it. To re-create the procedure, you need the original source of the
CREATE PROCEDUREstatement. Query system tables to extract the source of theCREATE PROCEDUREstatement to a file.The SQL
DROP PROCEDUREstatement deletes stored procedures from the database. Exercise care in dropping procedures, since any procedure that calls the dropped procedure will raise an error condition when the now nonexistent stored procedure is invoked.Stored procedure security
The following guidelines apply to stored procedure security:
- To create a stored procedure, a user must have
RESOURCEorDBAprivileges.- The
DBAprivilege entitles a user to execute any stored procedure.- The
DBAprivilege entitles a user to drop any stored procedure.- The owner of a stored procedure is given
EXECUTEprivilege on that procedure at creation time, by default.- The privileges on a procedure can be granted to another user or to public either by the owner of that procedure or by the DBA.
- Stored procedures are executed with the definer’s rights, not the invoker’s. In other words, when a procedure is being executed on behalf of a user with
EXECUTEprivilege on that procedure, for the objects that are accessed by the procedure, the procedure owner’s privileges are checked and not the user’s. This enables a user to execute a procedure successfully even when the user does not have the privileges to directly access the objects that are accessed by the procedure, as long as the user hasEXECUTEprivilege on the procedure.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |